<?php

class Core_Agent_Component_Subject_View_Concessions_Create extends Core_Agent_Share_View_Form {

    protected  function initialize() {
        $this->setTemplatePath('create');
        parent::initialize();
    }

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('state'=>'draft') ,'save') . "')");
        $group->addButton($this->__('share.button.submit'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('state'=>'pending') ,'save') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('concessions_form')
                ->addHiddenField('id', 'concessions[id]');
        $form->addTextboxField($this->__('share.label.name'), 'name', 'concessions[name]', TRUE)->addValidateRule('required');
        $form->addSelectField($this->__('promotion.label.concessions_category'), 'category_id', 'concessions[category_id]', TRUE)
                ->bindData($this->getCategory(), 'name', 'id')
                ->addValidateRule('required');
        $form->addDatetimeField($this->__('share.label.start_time'), 'start_time', 'concessions[start_time]')
                ->setFormat('Y-m-d');
        $form->addDatetimeField($this->__('share.label.end_time'), 'end_time', 'concessions[end_time]')
                ->setFormat('Y-m-d');
        $form->addSelectField($this->__('share.label.theme'), 'theme_id', 'concessions[theme_id]',TRUE)
                ->setOption('--', '')
                ->bindData($this->getThemes(), 'title', 'id');
        $form->addTextboxField($this->__('share.label.tag'), 'tag', 'concessions[tag]');
        $form->addSelectField('Poi', 'poi_ids', 'concessions[poi_ids][]')
                ->setOption('--','')
                ->bindData($this->getPois(),'shop_name','id')
                ->setSize(5)
                ->setMultiple(TRUE);
        $form->addTextboxField($this->__('promotion.label.condition'), 'condition', 'concessions[condition]');
        $form->addTextboxField($this->__('promotion.label.mode'), 'mode', 'concessions[mode]');
        $form->addFileField($this->__('share.label.preview_image'), 'picture', 'concessions[picture][]')->setMultiple(TRUE);
        $form->addTextareaField($this->__('share.label.detail'), 'detail', 'concessions[detail]');
        $form->addBooleanField($this->__('promotion.label.subject_recommend'), 'is_recommend', 'concessions[is_recommend]')
                ->setYesOption($this->__('status.boolean.1'))
                ->setNoOption($this->__('status.boolean.0'));
        $form->createTab('base_tab', $this->__('promotion.label.base_tab'),
                array('field_name', 'field_category_id', 'field_tag', 'field_theme_id', 'field_start_time', 'field_end_time',
                    'field_condition', 'field_mode', 'field_detail','field_is_recommend'));
        $form->createTab('picture_tab', $this->__('promotion.label.picture_tab'),
                array('field_picture'));
        $form->createTab('poi_tab', $this->__('promotion.label.poi_tab'),
                array('field_poi_ids'));
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
            $form->getInput('picture')
				 ->setBaseUrl($this->getRouter()->getBaseUrl().'pub/concessions/content/'.$entity->getId().'/');
            if(!empty($entity['picture'])){
                $form->getInput('picture')->setValue(explode(',', $entity->getPicture()));
            }
        }
        parent::buildForm($form);
    }


}